package com.xiguanlezz.cn.protocol;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/4 10:55
 * @Description：
 */
@Accessors(chain = true)
@Builder
@Getter
@Setter
@ToString
public class RpcHeader implements Serializable {
    private static final long serialVersionUID = -4439233679632760804L;

    /**
     * +---------------+---------------+-----------------+-------------+
     * |  Magic Number |  Message Type |  Message Status |  Message Id |
     * |    2 bytes    |    1 bytes    |     1 bytes     |   8 bytes   |
     * +---------------+---------------+-----------------+-------------+
     * |          Serializer Type        |          Data Length        |
     * |              16 bytes           |            4 bytes          |
     * +---------------------------------------------------------------+
     * +---------------+---------------+-----------------+-------------+
     * |                          Data Bytes                           |
     * |                   Length: ${Data Length}                      |
     * +---------------------------------------------------------------+
     */

    // 魔数，占2字节
    private short magicNumber;

    // 消息类型，占1字节
    private byte messageType;

    // 消息状态，占1字节
    private byte messageStatus;

    // 消息ID，占8字节
    private long messageId;

    // 序列化类型，占16字节（如果不足16字节则前面补#）
    private String serializerType;

    // 消息长度，占4字节
    private int dataLength;
}
